﻿using System;
using System.Collections.Generic;
using System.Data.SqlClient;
using System.Linq;
using System.Web;
using System.Web.Configuration;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class modify : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
      
    }
    protected void Button2_Click(object sender, EventArgs e)
    {
        Response.Redirect("https://www.google.com.tw/");
    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        int bd = 1;
        char sex = 'M';
        SqlConnection Conn = new SqlConnection(WebConfigurationManager.ConnectionStrings["testConnectionString"].ConnectionString);
        try
        {
            string s = "UPDATE [dbo].[user] SET user_username=@user_username, user_password=@user_password,user_first_name=@user_first_name,user_last_name=@user_last_name,user_birthday=@user_birthday,user_sex=@user_sex,user_mobile_phone=@user_mobile_phone,user_email=@user_email";

            SqlCommand sqlcmd = new SqlCommand(s, Conn);

            //宣告參數
            sqlcmd.Parameters.Add("@user_username", System.Data.SqlDbType.NVarChar);
            sqlcmd.Parameters.Add("@user_password", System.Data.SqlDbType.NVarChar);
            sqlcmd.Parameters.Add("@user_first_name", System.Data.SqlDbType.NChar);
            sqlcmd.Parameters.Add("@user_last_name", System.Data.SqlDbType.NChar);
            sqlcmd.Parameters.Add("@Birthdayuser_birthday", System.Data.SqlDbType.DateTime);
            sqlcmd.Parameters.Add("@user_sex", System.Data.SqlDbType.NVarChar);
            sqlcmd.Parameters.Add("@user_mobile_phone", System.Data.SqlDbType.NChar);
            sqlcmd.Parameters.Add("@user_email", System.Data.SqlDbType.NVarChar);


            //給參數作傳遞
            sqlcmd.Parameters["@user_username"].Value = TextBox6.Text;
            //sqlcmd.Parameters["@user_password"].Value = TextBoxPassword.Text;
            sqlcmd.Parameters["@user_first_name"].Value = TextBox1.Text;
            sqlcmd.Parameters["@user_last_name"].Value = TextBox2.Text;
            sqlcmd.Parameters["@Birthdayuser_birthday"].Value = TextBox3.Text;
            sqlcmd.Parameters["@user_mobile_phone"].Value = TextBox4.Text;
            sqlcmd.Parameters["@user_email"].Value = TextBox5.Text;
    
           

            if (RBSEX.Checked)
            {
                sex = 'F';
            }
            sqlcmd.Parameters["@user_sex"].Value = sex;
            sqlcmd.Connection.Open();

            try
            {
                sqlcmd.ExecuteNonQuery();
                this.Response.Redirect("TEST.aspx");
            }
            catch
            {
                Lb1_Msg.Text = "錯誤";

            }


        }
        finally
        {
            Conn.Close();
        }





        

    }
}